package com.joyd.joydlibexample

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
// import com.joyd.joydlib.dev.ScreenTapActivity 已替换为本地实现
import com.joyd.joydlibexample.ScreenTapExampleActivity
import com.joyd.joydlibexample.WebSocketExampleActivity

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                Surface(modifier = Modifier.fillMaxSize()) {
                    MainMenuScreen(
                        onWebSocketExampleClick = {
                            // 点击第一个按钮跳转到WebSocketExampleActivity
                            startActivity(Intent(this@MainActivity, WebSocketExampleActivity::class.java))
                        },
                        onScreenTapExampleClick = {
                            // 点击跳转到屏幕点击示例Activity
                            startActivity(Intent(this@MainActivity, ScreenTapExampleActivity::class.java))
                        }
                    )
                }
            }
        }
    }
}

@Composable
fun MainMenuScreen(
    onWebSocketExampleClick: () -> Unit,
    onScreenTapExampleClick: () -> Unit
) {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        // 标题
        Text(
            text = "JoydLib 示例应用",
            fontSize = 28.sp,
            modifier = Modifier.padding(bottom = 40.dp)
        )
        
        // 按钮组
        Column(
            verticalArrangement = Arrangement.spacedBy(16.dp),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Button(
                onClick = onWebSocketExampleClick,
                modifier = Modifier.padding(12.dp)
            ) {
                Text(
                    text = "WebSocket客户端示例",
                    fontSize = 18.sp
                )
            }
            
            Button(
                onClick = onScreenTapExampleClick,
                modifier = Modifier.padding(12.dp)
            ) {
                Text(
                    text = "屏幕点击功能示例",
                    fontSize = 18.sp
                )
            }
            
            Button(
                onClick = { /* 其他功能占位 */ },
                enabled = false,
                modifier = Modifier.padding(12.dp)
            ) {
                Text(
                    text = "更多功能即将推出",
                    fontSize = 18.sp
                )
            }
        }
    }
}